﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:APP_PROUNFORHOUINFO
	/// </summary>
	public partial class APP_PROUNFORHOUINFO : BaseDAL<GSLMS.Entity.TB_APP_PROUNFORHOUINFO>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public APP_PROUNFORHOUINFO()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_APP_PROUNFORHOUINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROCID", model.PROCID),
								new OracleParameter("P_REGINFOID", model.REGINFOID),
								new OracleParameter("P_RISKBYID", model.RISKBYID),
								new OracleParameter("P_RISKBYNAME", model.RISKBYNAME),
								new OracleParameter("P_LEGAL", model.LEGAL),
								new OracleParameter("P_LEGALTEL", model.LEGALTEL),
								new OracleParameter("P_LEGALTEL2", model.LEGALTEL2),
								new OracleParameter("P_CONBY", model.CONBY),
								new OracleParameter("P_CONBYTEL", model.CONBYTEL),
								new OracleParameter("P_CONBYTEL2", model.CONBYTEL2),
								new OracleParameter("P_CORPADDRESS", model.CORPADDRESS),
								new OracleParameter("P_REGAMOUNT", model.REGAMOUNT),
								new OracleParameter("P_MAINBUSS", model.MAINBUSS),
								new OracleParameter("P_REPAYMENT", model.REPAYMENT),
								new OracleParameter("P_USEFOR", model.USEFOR),
								new OracleParameter("P_ADVAMT", model.ADVAMT),
								new OracleParameter("P_BUSSBRIEF", model.BUSSBRIEF),
								new OracleParameter("P_LOANMODE", model.LOANMODE),
								new OracleParameter("P_REPAYSOURCE", model.REPAYSOURCE),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 23; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_app_prounforhouinfo_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_APP_PROUNFORHOUINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROCID", model.PROCID),
								new OracleParameter("P_REGINFOID", model.REGINFOID),
								new OracleParameter("P_RISKBYID", model.RISKBYID),
								new OracleParameter("P_RISKBYNAME", model.RISKBYNAME),
								new OracleParameter("P_LEGAL", model.LEGAL),
								new OracleParameter("P_LEGALTEL", model.LEGALTEL),
								new OracleParameter("P_LEGALTEL2", model.LEGALTEL2),
								new OracleParameter("P_CONBY", model.CONBY),
								new OracleParameter("P_CONBYTEL", model.CONBYTEL),
								new OracleParameter("P_CONBYTEL2", model.CONBYTEL2),
								new OracleParameter("P_CORPADDRESS", model.CORPADDRESS),
								new OracleParameter("P_REGAMOUNT", model.REGAMOUNT),
								new OracleParameter("P_MAINBUSS", model.MAINBUSS),
								new OracleParameter("P_REPAYMENT", model.REPAYMENT),
								new OracleParameter("P_USEFOR", model.USEFOR),
								new OracleParameter("P_ADVAMT", model.ADVAMT),
								new OracleParameter("P_BUSSBRIEF", model.BUSSBRIEF),
								new OracleParameter("P_LOANMODE", model.LOANMODE),
								new OracleParameter("P_REPAYSOURCE", model.REPAYSOURCE),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 23; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_app_prounforhouinfo_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_app_prounforhouinfo_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_APP_PROUNFORHOUINFO DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_APP_PROUNFORHOUINFO model = new GSLMS.Entity.TB_APP_PROUNFORHOUINFO();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROCID"]!=null && dr["PROCID"].ToString()!="")
				{
					model.PROCID=OracleHelper.ToLong(dr["PROCID"].ToString());
				}
				if(dr["REGINFOID"]!=null && dr["REGINFOID"].ToString()!="")
				{
					model.REGINFOID=OracleHelper.ToLong(dr["REGINFOID"].ToString());
				}
				if(dr["RISKBYID"]!=null && dr["RISKBYID"].ToString()!="")
				{
					model.RISKBYID=OracleHelper.ToLong(dr["RISKBYID"].ToString());
				}
				if(dr["RISKBYNAME"]!=null && dr["RISKBYNAME"].ToString()!="")
				{
					model.RISKBYNAME=dr["RISKBYNAME"].ToString();
				}
				if(dr["LEGAL"]!=null && dr["LEGAL"].ToString()!="")
				{
					model.LEGAL=dr["LEGAL"].ToString();
				}
				if(dr["LEGALTEL"]!=null && dr["LEGALTEL"].ToString()!="")
				{
					model.LEGALTEL=dr["LEGALTEL"].ToString();
				}
				if(dr["LEGALTEL2"]!=null && dr["LEGALTEL2"].ToString()!="")
				{
					model.LEGALTEL2=dr["LEGALTEL2"].ToString();
				}
				if(dr["CONBY"]!=null && dr["CONBY"].ToString()!="")
				{
					model.CONBY=dr["CONBY"].ToString();
				}
				if(dr["CONBYTEL"]!=null && dr["CONBYTEL"].ToString()!="")
				{
					model.CONBYTEL=dr["CONBYTEL"].ToString();
				}
				if(dr["CONBYTEL2"]!=null && dr["CONBYTEL2"].ToString()!="")
				{
					model.CONBYTEL2=dr["CONBYTEL2"].ToString();
				}
				if(dr["CORPADDRESS"]!=null && dr["CORPADDRESS"].ToString()!="")
				{
					model.CORPADDRESS=dr["CORPADDRESS"].ToString();
				}
				if(dr["REGAMOUNT"]!=null && dr["REGAMOUNT"].ToString()!="")
				{
					model.REGAMOUNT=OracleHelper.ToDecimal(dr["REGAMOUNT"].ToString());
				}
				if(dr["MAINBUSS"]!=null && dr["MAINBUSS"].ToString()!="")
				{
					model.MAINBUSS=dr["MAINBUSS"].ToString();
				}
				if(dr["REPAYMENT"]!=null && dr["REPAYMENT"].ToString()!="")
				{
                    model.REPAYMENT = OracleHelper.ToInt(dr["REPAYMENT"].ToString());
				}
				if(dr["USEFOR"]!=null && dr["USEFOR"].ToString()!="")
				{
					model.USEFOR=dr["USEFOR"].ToString();
				}
				if(dr["ADVAMT"]!=null && dr["ADVAMT"].ToString()!="")
				{
					model.ADVAMT=OracleHelper.ToDecimal(dr["ADVAMT"].ToString());
				}
				if(dr["BUSSBRIEF"]!=null && dr["BUSSBRIEF"].ToString()!="")
				{
					model.BUSSBRIEF=dr["BUSSBRIEF"].ToString();
				}
				if(dr["LOANMODE"]!=null && dr["LOANMODE"].ToString()!="")
				{
					model.LOANMODE=dr["LOANMODE"].ToString();
				}
				if(dr["REPAYSOURCE"]!=null && dr["REPAYSOURCE"].ToString()!="")
				{
					model.REPAYSOURCE=dr["REPAYSOURCE"].ToString();
				}
				if(dr["SPAREFIELD1"]!=null && dr["SPAREFIELD1"].ToString()!="")
				{
                    model.SPAREFIELD1 = OracleHelper.ToInt(dr["SPAREFIELD1"].ToString());
				}
				if(dr["SPAREFIELD2"]!=null && dr["SPAREFIELD2"].ToString()!="")
				{
					model.SPAREFIELD2=dr["SPAREFIELD2"].ToString();
				}
				if(dr["SPAREFIELD3"]!=null && dr["SPAREFIELD3"].ToString()!="")
				{
					model.SPAREFIELD3=dr["SPAREFIELD3"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_APP_PROUNFORHOUINFO GetByID(long ID)
		{
			GSLMS.Entity.TB_APP_PROUNFORHOUINFO sModel = new GSLMS.Entity.TB_APP_PROUNFORHOUINFO();
			string sql = "";
			sql = "select * from TB_APP_PROUNFORHOUINFO where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_APP_PROUNFORHOUINFO> GetList(GSLMS.Entity.TB_APP_PROUNFORHOUINFO searchParam)
		{
			var list=new List<GSLMS.Entity.TB_APP_PROUNFORHOUINFO>();
			DataTable dt = null;
			string tblName = "TB_APP_PROUNFORHOUINFO";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_APP_PROUNFORHOUINFO model = new GSLMS.Entity.TB_APP_PROUNFORHOUINFO();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

